<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 商品品牌操作功能
 * 
 * @package 	htdocs
 * @subpackage  quanliadmin
 * @author  	allen.qiang
 */

quanli_require('module/base/goodsHandler.class.php');

class pa_goodsBrand {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1: //商品品牌列表
                    $this->goodsBrandList();
                    break;

                case 2: //商品品牌添加
                case 3: //商品品牌编辑
                    $this->brandEdit( $_REQUEST['operFlg'] );
                    break;

				default:
                    $this->toError('参数错误');
                    break;

            }

        } else {

            $this->toError('参数错误');

        }

    }

    /**
     * 转跳到错误页
     * @param string $msg 错误信息
     */
    private function toError( $msg ) {

        global $G_PGLOB;

        $G_PGLOB->display_error_page( $msg );

    }

    /**
     * 商品品牌列表
     * @author kangronghua
     * 
     */
    private function goodsBrandList() {

        global $G_PGLOB;

        //品牌编辑权限
        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(503));

        $G_PGLOB->smarty->display('goods/brand_list.tpl');

    }

    /**
     * 品牌编辑 
     *
     */
    private function brandEdit( $operFlg ) {

    	global $G_PGLOB;

        if ( $operFlg == 2) {

            //实例化公共类
            $commHandler = new commHandler( $G_PGLOB->DBCA );

            //获得最大的排序序号
            $sort_num = $commHandler->getSortNum('goods_brand');
            if ($sort_num == 0) {
                $this->toError('参数错误');
            }

            $G_PGLOB->smarty->assign('sort_num' , $sort_num);

        } else {

            if (!isset($_REQUEST['brandID']) || !is_numeric($_REQUEST['brandID']) || $_REQUEST['brandID'] <= 0) {
                $this->toError('参数错误');
            }

            //实例化商品类
            $goodsHandler = new goodsHandler( $G_PGLOB->DBCA );

            //查询品牌信息
            $arg_array = array(
                'brandID' => $_REQUEST['brandID']
            );
            $goods_brand_array = $goodsHandler->searchGoodsBrand( $arg_array );
            if (!$goods_brand_array) {
                $this->toError('商品品牌信息没有找到');
            }

            $G_PGLOB->smarty->assign_by_ref('goods_brand_array', $goods_brand_array[0]);

        }

        $G_PGLOB->smarty->display('goods/brand_edit.tpl');

    } 
    
}